package android.activities;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;

public class ChangePasswordActivity extends Activity implements OnClickListener {
	
	int item;
	EditText text1, text2, text3, text4;
	
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.change_password);
        item = (int)BaseActivity._item;
        View button19 = findViewById(R.id.button19);
        button19.setOnClickListener(this);
        View button20 = findViewById(R.id.button20);
        button20.setOnClickListener(this);
        View button8 = findViewById(R.id.button8);
        button8.setOnClickListener(this);
        text1 = (EditText)findViewById(R.id.editText16);
        text2 = (EditText)findViewById(R.id.editText17);
        text3 = (EditText)findViewById(R.id.editText18);
        text4 = (EditText)findViewById(R.id.editText19);
        text1.setText(BaseActivity.base.getSource(item));
        text2.setText(BaseActivity.base.getName(item));
        text3.setText(BaseActivity.base.getPassword(item));
        text4.setText(BaseActivity.base.getNote(item));
    }
	
	public void onClick(View v) {		
		switch(v.getId()) {
    	case R.id.button19:
    		finish();
    		break;
    	case R.id.button20:    		
    		BaseActivity.base.changeValue(item, text1.getText().toString(), text2.getText().toString(), text3.getText().toString(), text4.getText().toString()); 
    		finish();
    		break;
    	case R.id.button8:
    		Random generator = new Random();
    		int dlugosc = generator.nextInt(7) + 6;
    		StringBuilder sb = new StringBuilder();
    		int znak;
    		for (int i = 0; i < dlugosc; i++)
    		{
    			znak = generator.nextInt(93) + 33;
    			sb.append((char) znak);
    		}
    		text3.setText(sb);
    		break;
    	}
	}

}
